import {
	createApp
} from 'vue'
import {
	createPinia
} from 'pinia'
import piniaPluginPersist from 'pinia-plugin-persist'
import './style.css'
import App from './App.vue'
import router from './router/routes'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import 'element-plus/dist/index.css'
import _axios from './utils/api/axios'
import _storage from './utils/storage'
import _common from './utils/common'
import config from '../config/env.js';
import { FormGenerator } from 'element-plus-generator'

const pinia = createPinia()
pinia.use(piniaPluginPersist)

const app = createApp(App)

app.component('FormGenerator', FormGenerator);
import formCreate from '@form-create/element-ui'
import FcDesigner from '@form-create/designer'
app.use(FcDesigner)
app.use(formCreate)

// element ui icon图标循环注册
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
	app.component(key, component)
}

// 全局参数
app.config.globalProperties._http = _axios
app.config.globalProperties._storage = _storage
app.config.globalProperties._common = _common
app.config.globalProperties._api = config.API_BASE_URL; //上传图片需要用到

// 路由守卫
router.beforeEach((to, from, next) => {
	try {
		next()
	} catch (e) {
		window.location.href = "https://so.csdn.net/so/search?q=" + e.message
	}
});

// 挂载
app.use(ElementPlus, {
	locale: zhCn,
})
app.use(router)
app.use(pinia)
app.mount('#app')